from google.appengine.api import mail
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
#import logging
import email
import codecs

##############################################################

#change your information
appid = 'yourappid'
SendNoticeMail = 'notice@139.com'

##############################################################

class MailHandler(InboundMailHandler):
	def receive(self, msg):
		MailTo = msg.to
		sender = 'send@'+appid+'.appspotmail.com'
		if MailTo == sender:
			#logging.info('A self mail.')
			subject = msg.subject
			body = msg.body
		else:
			From = msg.sender
			#logging.info('from is ' + From)
			subject = From + ' send a new mail.'
			body = 'check it.'
		mail.send_mail(sender, SendNoticeMail, subject, body)


application = webapp.WSGIApplication([
  MailHandler.mapping()
], debug=True)

def main():
    run_wsgi_app(application)
    
if __name__ == "__main__":
    main()
